import dynamic from 'next/dynamic'
import { getIdFromSlug, getNameFromSlug } from '@/core/utils/slug'
import { useRouter } from 'next/router'
import _ from 'lodash'
import Seo from '@/core/components/Seo'

const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'))
const ProductSearch = dynamic(() => import('@/lib/product/components/ProductSearch'))

export default function CategoryDetail() {
  const router = useRouter()
  const { slug = '' } = router.query

  const categoryName = getNameFromSlug(slug)
  const categoryId = getIdFromSlug(slug)
  const query = {
    fq: `manufacture_id_i:${categoryId}`
  }
  return (
    <BasicLayout>
      <Seo
        title={`Beli ${categoryName} di Indoteknik`}
        description={`Jual ${categoryName} Kirim Jakarta Surabaya Semarang Makassar Manado Denpasar Balikpapan Medan Palembang Lampung Bali Bandung Makassar Manado.`}
        additionalMetaTags={[
          {
            property: 'keywords',
            content: `Jual ${categoryName}, harga ${categoryName}, ${categoryName} murah, toko ${categoryName}, ${categoryName} jakarta, ${categoryName} surabaya`
          }
        ]}
      />

      {!_.isEmpty(router.query) && (
        <ProductSearch
          query={query}
          prefixUrl={`/shop/category/${slug}`}
        />
      )}
    </BasicLayout>
  )
}
